home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / resplay1.zip / EXAMPLE.C next >
Text File  |  1991-01-09  |  3KB  |  108 lines

  1. /*********************************************************************
  2.  * Example program to show how easy it is to use RESPLAY from within
  3.  * any program.. consult your manual on how to do it inside BASIC,
  4.  * PASCAL, C, (assembler is ever easier)
  5.  *
  6.  * This program is Public Domain. Do with it anything you want as
  7.  * long as you keep my name in the header! (Send me a copy if its good!)
  8.  *
  9.  * Mark J Cox. December 1990.
  10.  * 8/1/91: Fixed bug that caused FREAD to stop at a ^Z (Used "+rb" !)
  11.  *
  12.  * (Written in Turbo C - Must be compiled using LARGE model)
  13.  *********************************************************************/
  14.  
  15. /* Allocates as much memory as possible, reads in a file and then
  16.    plays it through the speaker.  Unfortunately, FREAD seems to stop
  17.      at 64k... I don't know enough about C to get around this, I'm sure
  18.      someone else will though!                                         */
  19.  
  20. #include <alloc.h>
  21. #include <stdio.h>
  22. #include <dos.h>
  23.  
  24. #define MAGIC       0x7746
  25. #define CHECK_INST  0x8201
  26. #define RESPLAY     0x2f
  27. #define SETUP       0x8210
  28. #define PLAYER      0x8200
  29. #define SUCESS      0x1000
  30. #define FAILED      0x2000
  31. #define PLAY        0
  32. #define SPEAKER     4
  33. #define LPT2        1
  34. #define SAMPLE      1
  35.  
  36. FILE *stream;
  37. int do_it (int,int,int,unsigned int,unsigned int,unsigned int,unsigned int);
  38.  
  39. /*---------------------------------------------------------------*/
  40.  
  41. int do_it(  int mode, int device, int speed,
  42.     unsigned int st_msb, unsigned int st_lsb,
  43.     unsigned int len_msb, unsigned int len_lsb)
  44. {
  45.      union REGS inregs,outregs;
  46.  
  47.      inregs.x.ax = SETUP;           inregs.h.cl = mode;
  48.      inregs.h.bl = device;            inregs.h.bh = speed;
  49.      int86(RESPLAY,&inregs,&outregs);
  50.      if (outregs.x.ax==SUCESS)
  51.      {
  52.          inregs.x.dx = st_msb;      inregs.x.di = st_lsb;
  53.          inregs.x.cx = len_msb;     inregs.x.bx = len_lsb;
  54.          inregs.x.ax = PLAYER;
  55.          int86(RESPLAY,&inregs,&outregs);
  56.      }
  57.      return (outregs.x.ax == SUCESS);
  58. }
  59. /*---------------------------------------------------------------*/
  60.  
  61. main()
  62. {
  63.     union REGS inregs,outregs;
  64.     unsigned int play_seg,play_off;
  65.     unsigned int len_msb, len_lsb;
  66.     long int size,to_alloc;
  67.     char far *buffer;
  68.  
  69.     inregs.x.ax=CHECK_INST;
  70.     int86(RESPLAY,&inregs,&outregs);
  71.     if (outregs.x.ax != MAGIC)
  72.     {
  73.          printf("Error: RESPLAY is not installed\n");
  74.          exit (1);
  75.     }
  76.     to_alloc = farcoreleft() - 40000;      /* Free Mem - 40k for C */
  77.     if ((buffer=farmalloc(to_alloc))==NULL)
  78.     {
  79.         printf("Cant Allocate Memory\n");
  80.         exit(0);
  81.     }
  82.     if ((stream=fopen("test.smp","rb+"))==NULL)
  83.     {
  84.         printf("Can't open file test.smp\n\n");
  85.         exit(1);
  86.     }
  87.     size = fread(buffer,sizeof(char),65535,stream);
  88.     printf("Example: Allocated %ldk bytes.  'test.smp' is %ldk bytes \n",
  89.         (to_alloc/1024),(size/1024));
  90.  
  91.         play_off = FP_OFF(buffer);   /* Get pointer in xxxx:yyyy form */
  92.     play_seg = FP_SEG(buffer);
  93.     len_msb = (size/65536);
  94.     len_lsb = size - len_msb*(size/65536);
  95.     fclose(stream);
  96.  
  97. /* Play through Speaker, 16.0kHz from play_seg:play_off for len_msb,len_lsb */
  98.  
  99.     if (!do_it (PLAY,SPEAKER, 16*4, play_seg, play_off , len_msb, len_lsb))
  100.     {
  101.         printf("Error\n");
  102.         exit(1);
  103.     }
  104.     farfree(buffer); /*Free alloced memory */
  105.     exit(0);
  106. }
  107. /*---------------------------------------------------------------*/
  108.